﻿using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using WebAPI.Filters;
using wt.wine.Application.Common.Models;
using wt.wine.Application.ManageOrderTable;
using wt.wine.Application.ManageOrderTable.Command;
using wt.wine.Application.ManageOrderTable.Queries;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;

namespace WebAPI.Controllers.V1
{
    [ApiController]
    [Route("[controller]/[action]")]
    public class ManageOrderTableController : ApiControllerBase
    {

        /// <summary>
        /// 添加订单发起出酒命令
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [PermissioneFilter("AddOrderInfo")]
        [HttpPost]
        public async Task<Json<string>> AddOrderInfo([FromBody] AddOrderInfoCommand command)
        {
            return await Mediator.Send(command);
        }

        /// <summary>
        /// 出酒回调
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Json<string>> Ordercallback([FromBody] OrdercallbackCommand command)
        {
            return await Mediator.Send(command);
        }

        /// <summary>
        /// 获取首页统计数据
        /// </summary>
        /// <returns></returns>
        [PermissioneFilter("GetOrderstatisticsByDaysQueries")]
        [HttpPost]
        public async Task<Json<GetOrderstatisticsByDaysDTO>> GetOrderstatisticsByDaysQueries()
        {
            GetOrderstatisticsByDaysQueries command = new GetOrderstatisticsByDaysQueries();
            return await Mediator.Send(command);
        }

        /// <summary>
        /// 【经销商】轮询查订单状态
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [PermissioneFilter("AddOrderInfo")]
        [HttpPost]
        public async Task<Json<int>> GetOrderStateByDeViceId([FromBody] GetOrderStateByDeViceIdQueries query)
        {
            return await Mediator.Send(query);
        }

        /// <summary>
        /// 【经销商|平台】销售日志
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [PermissioneFilter("ManageOrderTable")]
        [HttpPost]
        public async Task<Json<GetOrderTableListDTO>> GetOrderTableList([FromBody] GetOrderTableListQueries query)
        {
            return await Mediator.Send(query);
        }
    }
}
